from flask_restful import Resource

from restful.api__.session import  login_required_current_user_generate, \
    pid_required_target_post_generate
from restful.model.query import QueryMultipleInstances
from restful.model.tables import Comment
from restful.response import ResponseSuccess


class PostAllComments(Resource):
    @login_required_current_user_generate
    @pid_required_target_post_generate
    def get(self,target_post,current_user):
        comments = QueryMultipleInstances(Comment,{'pid':target_post.id})
        return ResponseSuccess(data=[{
            'cid':i.id,
            'uid':i.uid,
            'time':i.time,
            'content':i.content
        } for i in comments])